<?php
$stupidResponses=Array("a cookie","a fish","balogna","FISHY","donut","applesauce","gagglesnorf","a monkey","the square root of 2","pi","unknown","too complex for this bot","nonexistant","undefined","an apple",$sender,"1/0");

$letters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$numbers="01234567890";
$lettersAndNumbers=$letters.$numbers;
/*for($i=2;$i<sizeOf($messageA);$i++){
  $paramA[$i-2]=$messageA[$i];
}*/
if(command("randint")){
  $botInt=(int)$paramA[2];
  $topInt=(int)$paramA[3];
  if(empty($topInt)){
    $topInt=$botInt;
    $botInt=0;
  }
  $randInt=rand($botInt,$topInt);
  SendCommand("PRIVMSG $channel :$sender: $randInt");
} else if(command("randstr")){
  $randString="";
  $strLength=(int)$paramA[2];
  if($strLength>50){
    $strLength=50;
  }
  for($i=0;$i<$strLength;$i++){
    $randInt=rand(0,strlen($letters));
    $randLetter=$letters[$randInt];
    $randString.=$randLetter;
  }
  SendCommand("PRIVMSG $channel :$sender: $randString");
} else if(command("random")){
  $randString="";
  $strLength=(int)$paramA[2];
  if($strLength>50){
    $strLength=50;
  }
  for($i=0;$i<$strLength;$i++){
    $randInt=rand(0,strlen($lettersAndNumbers));
    $randChar=$lettersAndNumbers[$randInt];
    $randString.=$randChar;
  }
  SendCommand("PRIVMSG $channel :$sender: $randString");
} else if(command("coin")){
  $randInt=rand(0,1);
  SendCommand("PRIVMSG $channel :".chr(1)."ACTION flips a coin".chr(1));
  sleep(1);
  if($randInt==0){
    SendCommand("PRIVMSG $channel :$sender: It's heads!");
  } else {
    SendCommand("PRIVMSG $channel :$sender: It's tails!");
  }
} else if(command("dice")){
  $pa2=$paramA[2];
  $pa2Str=(string)$pa2;
  $pa2Int=(int)$pa2;
  echo "\n\n$pa2Str : $pa2Int\n\n";
  if($pa2Str==$pa2Int){
    if($pa2Str==="0"){
      $diceNumber=$paramA[2];
    } else {
      $diceNumber=(int)$paramA[2];
    }
  } else {
    $diceNumber=$paramA[2];
  }
  SendCommand("PRIVMSG $channel :".chr(1)."ACTION rolls a $diceNumber sided die".chr(1));
  if(is_int($diceNumber)){
    $randInt=rand(1,$diceNumber);
  } else {
    $randInt=$stupidResponses[rand(0,sizeOf($stupidResponses)-1)];
  }
  sleep(1);
  SendCommand("PRIVMSG $channel :$sender: The answer is $randInt!");
} else if(command("reverse")){
  $message=substr($buffer,strlen($bufferA[0]." PRIVMSG $channel :"));
  SendCommand("PRIVMSG $channel :$sender: ".strrev(substr($message,strlen($messageA[0]." ".$messageA[1]))));
}
?>